package tk.mynoteapp.dev.other.eliminateifelse.right.useassert;

import org.springframework.util.Assert;

import java.math.BigDecimal;

/**
 * 使用Assert优化类似判空抛异常的代码
 */
public class OrderService {
    public void wrongSave(String orderNo, BigDecimal totalPrice) {
        if (orderNo == null) {
            throw new RuntimeException("orderNo 不能为空");
        } else {
            if (totalPrice == null) {
                throw new RuntimeException("totalPrice 不能为空");
            } else {
                System.out.println("doSave");
            }
        }
    }

    /**
     * 使用Assert优化类似判空抛异常的代码
     * @param orderNo
     * @param totalPrice
     */
    public void rightSave(String orderNo, BigDecimal totalPrice) {
        Assert.notNull(orderNo, "orderNo 不能为空");
        Assert.notNull(totalPrice, "totalPrice 不能为空");
        System.out.println("doSave");
    }
}
